/** 
 理财直融指令
*/
import React, { PureComponent } from 'react';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Row, Col } from 'antd';
import { SecuritiesCodeC, codeType, InputNumberC } from '../../../../comps';
import FormItemLayout from './formItemLayout';
@Form.create()
class FinaFlockingTrade extends PureComponent {
  state = {
    securityCode: undefined, //证券代码
  };

  componentDidMount() {
    this.props.onRef(this);
  }

  UNSAFE_componentWillReceiveProps(nextProps) {}
  // 数量的change事件
  NumChange = (e) => {
    const { getFieldsValue, setFieldsValue } = this.props.form;
    const formValues = getFieldsValue();
    const fullPriceTemp = formValues.priceqj;
    if (e && fullPriceTemp) {
      setFieldsValue({
        parValueTotalqj: e * fullPriceTemp,
      });
    } else {
      setFieldsValue({
        parValueTotalqj: '',
      });
    }
  };
  // 全价价格的change事件
  fullPriceChange = (e) => {
    const { getFieldsValue, setFieldsValue } = this.props.form;
    const formValues = getFieldsValue();
    const amountTemp = formValues.amount;
    if (e && amountTemp) {
      setFieldsValue({
        parValueTotalqj: e * amountTemp,
      });
    } else {
      setFieldsValue({
        parValueTotalqj: '',
      });
    }
  };
  // 抛出的getInfo事件
  getInfo = () => {
    const {
      form: { validateFields, getFieldsValue },
    } = this.props;
    const formValues = getFieldsValue();
    let flag = false;
    let query = undefined;
    validateFields((errors) => {
      if (errors) {
        return;
      } else {
        flag = true;
      }
    });
    if (flag) {
      query = formValues;
      query.tradingcode = this.state.securityCode.tradingCode;
      return query;
    } else {
      return;
    }
  };
  render() {
    return (
      <div>
        <Form>
          <Row>
            <Col span={24} style={{ marginBottom: '10px' }}>
              <SecuritiesCodeC
                title='证券代码'
                dataIndex={'tradingcode'}
                form={this.props.form}
                rules={[{ required: true, message: '请选择证券代码' }]}
                codeType={codeType.lczr}
                extraLayout={FormItemLayout}
                onChange={(e) => {
                  this.setState({
                    securityCode: e,
                  });
                  this.props.tradingCodeOnChange(e);
                }}
              />
            </Col>
          </Row>
          <Row>
            <Col span={24} style={{ marginBottom: '10px' }}>
              <InputNumberC
                dataIndex='amount'
                title={'数量'}
                precision={0}
                min={0}
                splitStyle={true}
                rules={[
                  { required: true, message: '请输入' },
                  { pattern: /^[+-]?(\d){1,}0$/, message: '请输入10的倍数' },
                ]}
                form={this.props.form}
                formItemLayout={FormItemLayout}
                onChange={this.NumChange}
                unit='张'
              />
            </Col>
          </Row>
          <Row>
            <Col span={24} style={{ marginBottom: '10px' }}>
              <InputNumberC
                dataIndex='price'
                title={'净价价格'}
                precision={4}
                min={0.0001}
                splitStyle={true}
                rules={[
                  { required: true, message: '请输入' },
                  { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '请输入大于0' },
                ]}
                form={this.props.form}
                formItemLayout={FormItemLayout}
                unit='元'
              />
            </Col>
          </Row>
          <Row>
            <Col span={24} style={{ marginBottom: '10px' }}>
              <InputNumberC
                dataIndex='priceqj'
                title={'全价价格'}
                precision={4}
                min={0.0001}
                splitStyle={true}
                rules={[
                  { required: true, message: '请输入' },
                  { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '请输入大于0' },
                ]}
                form={this.props.form}
                formItemLayout={FormItemLayout}
                onChange={this.fullPriceChange}
                unit='元'
              />
            </Col>
          </Row>
          <Row>
            <Col span={24} style={{ marginBottom: '10px' }}>
              <InputNumberC
                dataIndex='parValueTotalqj'
                title={'全价总额'}
                precision={4}
                min={0.0001}
                splitStyle={true}
                rules={[{ required: true, message: '请输入' }]}
                form={this.props.form}
                formItemLayout={FormItemLayout}
                disabled={true}
                unit='元'
              />
            </Col>
          </Row>
        </Form>
      </div>
    );
  }
}
export default FinaFlockingTrade;
